<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
 * @method static create(array $validated)
 * @method static where(string $string, $id)
 * @method static find($id)
 */
class Comment extends Model
{
    use HasFactory;
    protected $table = "tb_comment";
    protected $primaryKey = "comm_id";
    public const UPDATED_AT = "comm_update_time";
    public const CREATED_AT = "comm_create_time";
    protected $fillable = [
        "post_id", "parent_id", "comm_content",
        "comm_is_show", "comm_name", "comm_email"
    ];

    public function posts(): HasOne
    {
        return $this->hasOne("App\Models\Post", "post_id", "post_id");
    }

    public function children(): HasMany
    {
        return $this->hasMany("App\Models\Comment", "parent_id", "comm_id");
    }
}
